package com.corpgovernment.organization.dataloader;

import com.corpgovernment.api.ordercenter.dto.budget.OrderBudgetRequestDto;
import com.corpgovernment.api.ordercenter.dto.budget.QueryOrderDetailResponse;
import com.corpgovernment.api.ordercenter.soa.IOrderMonitorClient;
import com.corpgovernment.common.base.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author Ks.Xing
 * <p>
 * description:
 * create: 2023-03-22 17:22
 */
@Slf4j
@Component
public class OrderClientLoader {
    @Autowired
    private IOrderMonitorClient iOrderMonitorClient;

    public List<QueryOrderDetailResponse> getFlightPassData (OrderBudgetRequestDto requestDto) {
        JSONResult<List<QueryOrderDetailResponse>> orderInfoByOrderId = iOrderMonitorClient.getOrderBudgetAmountByOrder(requestDto);

        if (orderInfoByOrderId == null || orderInfoByOrderId.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(orderInfoByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
            return Collections.emptyList();
        }
        return orderInfoByOrderId.getData();
    }

    public List<QueryOrderDetailResponse> getInflFlightPassData(OrderBudgetRequestDto requestDto) {
        JSONResult<List<QueryOrderDetailResponse>> orderInfoByOrderId = iOrderMonitorClient.getInflFlightOrderBudgetAmountByOrder(requestDto);

        if (orderInfoByOrderId == null || orderInfoByOrderId.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(orderInfoByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
            return Collections.emptyList();
        }
        return orderInfoByOrderId.getData();
    }

    public List<QueryOrderDetailResponse> getHotelPassData(OrderBudgetRequestDto requestDto) {
        JSONResult<List<QueryOrderDetailResponse>> orderInfoByOrderId = iOrderMonitorClient.getHotelOrderBudgetAmountByOrder(requestDto);

        if (orderInfoByOrderId == null || orderInfoByOrderId.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(orderInfoByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
            return Collections.emptyList();
        }
        return orderInfoByOrderId.getData();
    }

    public List<QueryOrderDetailResponse> getiHotelPassData(OrderBudgetRequestDto requestDto) {
        JSONResult<List<QueryOrderDetailResponse>> orderInfoByOrderId = iOrderMonitorClient.getiHotelOrderBudgetAmountByOrder(requestDto);

        if (orderInfoByOrderId == null || orderInfoByOrderId.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(orderInfoByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
            return Collections.emptyList();
        }
        return orderInfoByOrderId.getData();
    }

    public List<QueryOrderDetailResponse> getTrainPassData(OrderBudgetRequestDto requestDto) {
        JSONResult<List<QueryOrderDetailResponse>> orderInfoByOrderId = iOrderMonitorClient.getTrainOrderBudgetAmountByOrder(requestDto);

        if (orderInfoByOrderId == null || orderInfoByOrderId.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(orderInfoByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
            return Collections.emptyList();
        }
        return orderInfoByOrderId.getData();
    }
}
